package com.business.business.controller;

import com.business.business.entity.OepreStore;
import com.business.business.entity.OepreUser;
import com.business.business.entity.Result;
import com.business.business.service.OePreStoreService;
import com.business.business.service.OepreUserService;
import com.business.business.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("store")
public class IndexController {
    @Autowired
   private OePreStoreService oePreStoreService;
    @Autowired
    private OepreUserService oepreUserService;


    @GetMapping("getstore")
    public Result getMyStore(int id){


        List<OepreStore> oplist =oePreStoreService.findOepreStoreByVouserid(id);
        if (oplist.size()>0){

            return Result.ok(oplist);
        }

        return  Result.errorMsg("您还没有商家");
    }


    @PostMapping("/doAdd")
    public Result doAdd(@RequestBody OepreStore oepreStore){
         if (StringUtil.isEmpty(oepreStore.getName())||StringUtil.isEmpty(oepreStore.getSeat())){

             return  Result.errorMsg("缺失参数");
         }

         oepreStore.setFlag(0);

        OepreStore oepreStoreResult   = oePreStoreService.saveOepreStore(oepreStore);

       return  Result.ok(oepreStoreResult);
    }

    @GetMapping("/getSorePrice")
    public Result doAdd(@RequestParam String parentid){

        if (StringUtil.isEmpty(parentid)){

            return  Result.errorMsg("缺失参数");
        }
        System.out.println(parentid);

       List<OepreUser> oepreUsers= oepreUserService.findOepreUserByParentid(parentid);


        if (oepreUsers.isEmpty()){

            return Result.errorMsg("您的商家还没有会员");
        }

        return  Result.ok(oepreUsers);
    }



}
